#pragma once
#include <string>
#include <vector>
#include <tchar.h>
#include <ms/str_camp/str_camp.h>

namespace ms{
    class Transcoding{
    public:
        static std::string utf8toansi(const char* utf8str)
        {
            if (!utf8str)
            {
                return "";
            }
            int buffLen = 0;
            const int MAX = strlen(utf8str) * 2 + 2;
            std::vector<wchar_t> wbuff;
            wbuff.resize(MAX);
            MultiByteToWideChar(CP_UTF8, 0, utf8str, -1, wbuff.data(), MAX);
            buffLen = WideCharToMultiByte(CP_ACP, 0, wbuff.data(), -1, NULL, 0, 0, 0);
            std::vector<char> gb2312;
            gb2312.resize(buffLen + 1);
            WideCharToMultiByte(CP_ACP, 0, wbuff.data(), -1, (LPSTR)gb2312.data(), buffLen, 0, 0);
            return gb2312.data();
        }

    };
}